<template>
    <div>
        <div class="header-abs" v-show="showAbs">
          <router-link tag="div" class="iconfont icon-back" to="/">&#xe658;</router-link>
        </div>
        <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
          <div class="iconfont icon-back" @click="back">&#xe658;</div>
          <p>景点详情</p>
        </div>
    </div>
</template>
<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      let top = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
      // console.log(top)
      if (top > 60) {
        this.showAbs = false
      } else {
        this.showAbs = true
      }
      let opacity = top / 140
      opacity = opacity > 1 ? 1 : opacity
      this.opacityStyle.opacity = opacity
    },
    back () {
      this.$router.push('/')
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  destroyed () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>
<style lang="stylus" scoped>
@import '~@/assets/styles/varibles.styl';
.header-abs
  width .8rem
  height .8rem
  line-height .8rem
  border-radius .4rem
  color #fff
  position fixed
  top .2rem
  left .2rem
  text-align center
  background-color #000
  .icon-back
    font-size .6rem
.header-fixed
    z-index 2
    position fixed
    height $headerHeight
    font-size .32rem
    background-color $bgColor
    color #fff
    text-align center
    top 0
    left 0
    right 0
    p
        line-height $headerHeight
        margin 0 auto
    .icon-back
        width .64rem
        position absolute
        left 0
        font-size .56rem
        top .12rem
</style>
